package controller;

import constant.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Article;
import pojo.Category;
import pojo.Page;
import pojo.User;
import service.IArticleService;
import service.ICategoryService;
import service.IUserService;
import util.MailUtil;
import util.PageModuleUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static constant.Constant.DEFAULT_PAGE_SIZE_BIG;

/**
 * 不需要权限也能访问的路径
 */
@Controller
public class VisitorController {
    @Autowired
    private IArticleService articleService;
    @Autowired
    private IUserService userService;
    @Autowired
    private ICategoryService categoryService;

    /**
     * 获得回帖周榜
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/visitor/top/reply/",method = RequestMethod.POST)
    public Map getReplyTop(int limit){
        Map map = new HashMap();
        List<User> replyTop = userService.getReplyTop(limit);
        map.put("data",replyTop );
        map.put("status", 0);
        return map;
    }
    @ResponseBody
    @RequestMapping("/visitor/sign/status")
    public Map getUserStatus(HttpServletRequest request){
        Map map = new HashMap();
        User user = (User) request.getSession().getAttribute("user");
        if (user==null){
            map.put("msg","未登录" );
            map.put("status",0 );
        }else {
            //数据封装
            Map data = new HashMap();
            //连续登陆天数
            data.put("days","4");
            //
            data.put("experience",5);
            //
            data.put("sign",false );
            //
            data.put("token", " ");

            //数据提交
            map.put("status",0 );
            map.put("data",data );

        }
        return map;
    }
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String goIndexPage(Model model) {
        //获取置顶内容
        List<Article> articles = articleService.getArticlesByTop(4);
        model.addAttribute("top",articles );
        getGeneralByCategory_Solved_Wonderful_Filter(null,null ,null ,Constant.ARTICLE_FILTER_CPX,"/column/all","page",1 , DEFAULT_PAGE_SIZE_BIG,model );

        return "index";
    }
    @RequestMapping(value = "/visitor/forget", method = RequestMethod.GET)
    public String goForgetPage(User user,String token,Model model,HttpServletRequest request) {
        if(user.getUserMail()==null||token==null){
            //忘记密码页面
            return "user/forget";
        }else{
            //修改密码页面
            user = userService.getUserByMail(user.getUserMail());
            model.addAttribute("forget", user);
            PageModuleUtil.set(request,Constant.PAGE_INDEX);
        }
        return "user/forget";
    }
    @ResponseBody
    @RequestMapping(value = "/visitor/forget", method = RequestMethod.POST)
    public Map findPasswordByMail(String email,String vercode,HttpServletRequest request) {
        Map map = new HashMap();
        //判断邮箱

        //发送邮件
        if(request.getSession().getAttribute("vercode").equals(vercode)){
            User userByMail = userService.getUserByMail(email);
            if(userByMail==null){
                map.put("status",0 );
                map.put("msg","该邮箱并未注册" );
                return map;
            }
            String token = System.currentTimeMillis()+"";
            String url = "http://localhost:8080/visitor/forget?userMail=" + email+"&token=" +token;
            String message = "您正在进行邮箱密码找回，点击以下链接修改密码" + url;
            boolean sendMail = MailUtil.sendMail(email, message);
            if(sendMail){
                map.put("status",0 );
                map.put("msg","已将密码重置地址发送至您的邮箱，<br>" +
                        "请注意查收" );
                request.getSession().setAttribute("token",token );
                return map;
            }else {
                map.put("status",0 );
                map.put("msg","邮箱发送失败" );
                return map;
            }
        }
        map.put("status",0 );
        map.put("msg","验证码错误" );
        return map;
    }

    /**
     * 用户通过找回密码方式修改密码
     * @param user
     * @param pass
     * @param repass
     * @param token
     * @param vercode
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/visitor/repass",method = RequestMethod.POST)
    public Map modifyInformation(User user, String pass, String repass,String token,String vercode, HttpServletRequest request){
        Map map = new HashMap();
        //验证码效验
        if(!request.getSession().getAttribute("vercode").equals(vercode)){
            map.put("status", 1);
            map.put("msg", "验证码错误");
            return map;
        }
        //密码效验
        if(pass==null||repass==null||!pass.equals(repass)){
            map.put("status", 1);
            map.put("msg","两次密码不一致" );
            return map;
        }
        //合法性效验
        String tokenMark = (String) request.getSession().getAttribute("token");
        if(!token.equals(tokenMark)){
            map.put("status", 1);
            map.put("msg","无权修改" );
            return map;
        }
        //密码保存到数据库
        user.setUserPassword(pass);
        int i = userService.modifyPasswordById(user);
        if(i==1){
            request.getSession().removeAttribute("token");
            map.put("status",0 );
            map.put("action","/user/login/" );
            map.put("msg","密码修改成功" );
            return map;
        }
        map.put("status", 1);
        map.put("msg", "修改密码失败");
        return map;
    }
    @RequestMapping("/a")
    public String test(){
        return "redirect:/WEB-INF/view/common/tips.jsp";
    }


    /**
     * 首页 综合
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/all/",method = RequestMethod.GET)
    public String getFirstPageArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter(null,null ,null ,Constant.ARTICLE_FILTER_CPX,"/column/all","page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 首页 综合 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/all/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPagePageArticles(@PathVariable(value = "pageCurrent") int pageCurrent, Model model){
        getGeneralByCategory_Solved_Wonderful_Filter(null,null ,null ,Constant.ARTICLE_FILTER_CPX,"/column/all","page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }


    /**
     * 首页 未解决
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/all/unsolved/",method = RequestMethod.GET)
    public String getFirstPageUnsolvedArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter(null, 0,null ,Constant.ARTICLE_FILTER_UNSOLVED,"/column/all","unsolved/page" ,1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 首页 未解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/all/unsolved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageUnsolvedArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter(null, 0,null ,Constant.ARTICLE_FILTER_UNSOLVED,"/column/all","unsolved/page" ,pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 首页 已结
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/all/solved/",method = RequestMethod.GET)
    public String getFirstPageSolvedArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter(null, 1, null,Constant.ARTICLE_FILTER_SOLVED ,"/column/all","solved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 首页 解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/all/solved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageSolvedArticles(@PathVariable(value = "pageCurrent") int pageCurrent, Model model){
        getGeneralByCategory_Solved_Wonderful_Filter(null, 1,null ,Constant.ARTICLE_FILTER_SOLVED ,"/column/all","solved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 首页 精贴
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/all/wonderful/",method = RequestMethod.GET)
    public String getFirstPageWonderfulArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter(null, null, 1,Constant.ARTICLE_FILTER_WONDERFUL,"/column/all" ,"wonderful/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 首页 精贴 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/all/wonderful/page/{pageCurrent}/")
    public String getCurrentPageWonderfulArticles(@PathVariable(value = "pageCurrent") int pageCurrent, Model model){
        getGeneralByCategory_Solved_Wonderful_Filter(null, null, 1,Constant.ARTICLE_FILTER_WONDERFUL,"/column/all" ,"wonderful/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 提问 综合
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/quiz/",method = RequestMethod.GET)
    public String getFirstPageQuizArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 1,null ,null ,Constant.ARTICLE_FILTER_CPX ,"/column/quiz","page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 提问 综合 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/quiz/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageQuizArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 1,null ,null ,Constant.ARTICLE_FILTER_CPX ,"/column/quiz","page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 提问 未解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/quiz/unsolved/",method = RequestMethod.GET)
    public String getFirstPageUnsolvedQuizArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 1, 0, 0, Constant.ARTICLE_FILTER_UNSOLVED,"/column/quiz" , "unsolved/page", 1, DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 提问 未解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/quiz/unsolved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageUnsolvedQuizArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 1, 0, 0, Constant.ARTICLE_FILTER_UNSOLVED,"/column/quiz" , "unsolved/page", pageCurrent, DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 提问 解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/quiz/solved/",method = RequestMethod.GET)
    public String getFirstPageSolvedQuizArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 1, 1, 0, Constant.ARTICLE_FILTER_SOLVED,"/column/quiz" , "unsolved/page", 1, DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 提问 解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/quiz/solved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageSolvedQuizArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 1, 1, 0, Constant.ARTICLE_FILTER_SOLVED,"/column/quiz" , "unsolved/page", pageCurrent, DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 提问 精贴 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/quiz/wonderful/",method = RequestMethod.GET)
    public String getFirstPageWonderfulQuizArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 1, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/quiz" , "solved/page", 1, DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 提问 精贴 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/quiz/wonderful/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageWonderfulQuizArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 1, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/quiz" , "solved/page", pageCurrent, DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 分享 综合 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/share/",method = RequestMethod.GET)
    public String getFirstPageShareArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 2, null, null, Constant.ARTICLE_FILTER_CPX,"/column/share","page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 分享 综合 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/share/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageShareArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 2, null, null, Constant.ARTICLE_FILTER_CPX,"/column/share","page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 分享 未解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/share/unsolved",method = RequestMethod.GET)
    public String getFirstPageUnsolvedShareArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 2, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/share","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 分享 未解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/share/unsolved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageUnsolvedShareArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 2, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/share","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 分享 解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/share/solved",method = RequestMethod.GET)
    public String getFirstPageSolvedShareArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 2, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/share","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 分享 解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/share/solved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageSolvedShareArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 2, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/share","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 分享 精贴 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/share/wonderful",method = RequestMethod.GET)
    public String getFirstPageWonderfulShareArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 2, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/share","wonderful/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 分享 精贴 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/share/wonderful/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageWonderfulShareArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 2, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/share","wonderful/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 讨论 综合 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/discuss/",method = RequestMethod.GET)
    public String getFirstPageDiscussArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 3, null, null, Constant.ARTICLE_FILTER_CPX,"/column/discuss","page",1 , DEFAULT_PAGE_SIZE_BIG,model );

        return "jie/index";
    }

    /**
     * 讨论 综合 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/discuss/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageDiscussArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 3, null, null, Constant.ARTICLE_FILTER_CPX,"/column/discuss","page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 讨论 未解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/discuss/unsolved",method = RequestMethod.GET)
    public String getFirstPageUnsolvedDiscussArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 3, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/discuss","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 讨论 未解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/discuss/unsolved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageUnsolvedDiscussArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 3, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/discuss","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 讨论 解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/discuss/solved",method = RequestMethod.GET)
    public String getFirstPageSolvedDiscussArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 3, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/discuss","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 讨论 解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/discuss/solved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageSolvedDiscussArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 3, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/discuss","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 讨论 精贴 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/discuss/wonderful",method = RequestMethod.GET)
    public String getFirstPageWonderfulDiscussArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 3, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/discuss","wonderful/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 讨论 精贴 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/discuss/wonderful/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageWonderfulDiscussArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 3, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/discuss","wonderful/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 建议 综合 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/suggest/",method = RequestMethod.GET)
    public String getFirstPageSuggestArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 4, null, null, Constant.ARTICLE_FILTER_CPX,"/column/suggest","page",1 , DEFAULT_PAGE_SIZE_BIG,model );

        return "jie/index";
    }

    /**
     * 建议 综合 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/suggest/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageSuggestArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 4, null, null, Constant.ARTICLE_FILTER_CPX,"/column/suggest","page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 建议 未解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/suggest/unsolved",method = RequestMethod.GET)
    public String getFirstPageUnsolvedSuggestArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 4, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/suggest","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 建议 未解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/suggest/unsolved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageUnsolvedSuggestArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 4, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/suggest","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 建议 解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/suggest/solved",method = RequestMethod.GET)
    public String getFirstPageSolvedSuggestArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 4, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/suggest","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 建议 解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/suggest/solved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageSolvedSuggestArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 4, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/suggest","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 建议 精贴 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/suggest/wonderful",method = RequestMethod.GET)
    public String getFirstPageWonderfulSuggestArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 4, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/suggest","wonderful/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 建议 精贴 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/suggest/wonderful/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageWonderfulSuggestArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 4, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/suggest","wonderful/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 公告 综合 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/notice/",method = RequestMethod.GET)
    public String getFirstPageNoticeArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 5, null, null, Constant.ARTICLE_FILTER_CPX,"/column/notice","page",1 , DEFAULT_PAGE_SIZE_BIG,model );

        return "jie/index";
    }

    /**
     * 公告 综合 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/notice/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageNoticeArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 5, null, null, Constant.ARTICLE_FILTER_CPX,"/column/notice","page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 公告 未解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/notice/unsolved",method = RequestMethod.GET)
    public String getFirstPageUnsolvedNoticeArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 5, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/notice","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 公告 未解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/notice/unsolved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageUnsolvedNoticeArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 5, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/notice","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 公告 解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/notice/solved",method = RequestMethod.GET)
    public String getFirstPageSolvedNoticeArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 5, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/notice","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 公告 解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/notice/solved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageSolvedNoticeArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 5, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/notice","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 公告 精贴 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/notice/wonderful",method = RequestMethod.GET)
    public String getFirstPageWonderfulNoticeArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 5, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/notice","wonderful/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 公告 精贴 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/notice/wonderful/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageWonderfulNoticeArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 5, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/notice","wonderful/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 动态 综合 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/news/",method = RequestMethod.GET)
    public String getFirstPageNewsArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 6, null, null, Constant.ARTICLE_FILTER_CPX,"/column/news","page",1 , DEFAULT_PAGE_SIZE_BIG,model );

        return "jie/index";
    }

    /**
     * 动态 综合 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/news/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageNewsArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 6, null, null, Constant.ARTICLE_FILTER_CPX,"/column/news","page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 动态 未解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/news/unsolved",method = RequestMethod.GET)
    public String getFirstPageUnsolvedNewsArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 6, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/news","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 动态 未解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/news/unsolved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageUnsolvedNewsArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 6, 0, null, Constant.ARTICLE_FILTER_UNSOLVED,"/column/news","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 动态 解决 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/news/solved",method = RequestMethod.GET)
    public String getFirstPageSolvedNewsArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 6, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/news","unsolved/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 动态 解决 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/news/solved/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageSolvedNewsArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 6, 1, null, Constant.ARTICLE_FILTER_SOLVED,"/column/news","unsolved/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }
    /**
     * 动态 精贴 第一页
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/news/wonderful",method = RequestMethod.GET)
    public String getFirstPageWonderfulNewsArticles(Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 6, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/news","wonderful/page",1 , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 动态 精贴 分页
     * @param pageCurrent
     * @param model
     * @return
     */
    @RequestMapping(value = "/column/news/wonderful/page/{pageCurrent}/",method = RequestMethod.GET)
    public String getCurrentPageWonderfulNewsArticles(@PathVariable(value = "pageCurrent") int pageCurrent,Model model){
        getGeneralByCategory_Solved_Wonderful_Filter((byte) 6, null, 1, Constant.ARTICLE_FILTER_WONDERFUL,"/column/news","wonderful/page",pageCurrent , DEFAULT_PAGE_SIZE_BIG,model );
        return "jie/index";
    }

    /**
     * 按照类别 是否已结 是否精贴 查询数据，并设置选择的类别、状态
     * @param categoryId 类别
     * @param solved    是否结贴
     * @param wonderful 是否精贴
     * @param filter    状态
     * @param baseUrl   基本路径
     * @param additionalUrl 后置路径
     * @param pageCurrent   查询的页数
     * @param pageSize  数据条数
     * @param model 返回前台的数据封装
     */
    private void getGeneralByCategory_Solved_Wonderful_Filter(Byte categoryId,Integer solved,Integer wonderful,String filter,String baseUrl,String additionalUrl,int pageCurrent,int pageSize,Model model){
        //获取热议内容
        List<Article> articles = articleService.getArticlesByCommentNumber(pageCurrent,pageSize);
        model.addAttribute("hotda", articles);
        //封装对象
        Article article = new Article();
        article.setArticleCategoryId(categoryId);
        article.setArticleOver(solved);
        article.setArticleStar(wonderful);
        //获取相应条件的数据
        articles = articleService.getArticlesByMany(article,pageCurrent,pageSize);
        //封装到page对象中
        int count = articleService.getArticleCountByMany(article);
        Page<List<Article>> page = new Page<>(pageSize, count);
        page.setContent(articles);
        page.setPageCurrent(pageCurrent);
        page.setBaseUrl(baseUrl);
        page.setAdditionalUrl(additionalUrl);
        model.addAttribute("page",page );
        //获取类别
        List<Category> categories = categoryService.getAllCategory();
        model.addAttribute("categories",categories );
        //设置选择的filter 综合 已结 未结 精华
        model.addAttribute("filter",filter );
        //设置选择类别
        if(categoryId==null){
            categoryId = 0;
        }
        model.addAttribute("category_id","category-"+categoryId);
    }
    @RequestMapping("**")
    public String notFind(HttpServletRequest request){
        PageModuleUtil.set(request, Constant.PAGE_INDEX);
        return "other/404";
    }
}
